# Maintainer: Alexey Pavlov <Alexpux@gmail.com>
# Contributor: Paul Moore <p.f.moore@gmail.com>

_realname=sed
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.4
pkgrel=1
pkgdesc="Sed is a stream editor (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://www.gnu.org/software/sed/'
license=('GPL3')
depends=("${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-libssp")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=('strip' '!libtool' 'staticlibs')
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.xz"{,.sig}
        msvc_invalid_parameter_handler.patch)
sha256sums=('cbd6ebc5aaf080ed60d0162d7f6aeae58211a1ee9ba9bb25623daa6cd942683b'
            'SKIP'
            'f53f59031fe9f0e37c8cf358ab16a7c6a887df84085e7c146f30282ca9bff243')
validpgpkeys=('155D3FC500C834486D1EEA677FD9FCCB000BEEEE') # Jim Meyering <jim@meyering.net>

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/msvc_invalid_parameter_handler.patch"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  LDFLAGS+=" -fstack-protector" \
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}
  make install DESTDIR="${pkgdir}"

  # Licenses
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/README"                 "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/README"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING"                "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
